<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="author" content="wangyupeng">
	<title>不记名卡售卡</title>
	<script language="javascript" src="../script/common.js" type="text/javascript"></script>
	<script language="javascript" src="../script/card.js" type="text/javascript"></script>
	<script language="javascript" type="text/javascript" src="../script/print.js"></script>
	<script language="javascript" type="text/javascript" src="../script/pivot.js"></script>
<script language="javascript" type="text/javascript">
	//页面加载方法
	var sData;
	function load(){
		Eui.showNavigation();
		setPages(["readcardview","detview"]);
		Common.initDict(readCardForm.paymentType,Common.getSubsetItems("pay_type",[Constants.PAYMENT_CASH,Constants.PAYMENT_BANK]),"请选择");
		initActiveX();
	}
	
	//读卡
	function onReadCard(){
		try{
			var data = CardMgnt.findCard(readCardForm)
			CardMgnt.throwIssueErr(data.card,data.cardType,Constants.ANONYMOUS);
			$("issueCardbtn").disabled = false;
			
			var fee = CardMgnt.getFee(Constants.ACCOUNT_FEE_SELL_CARD,data.cardType.id);
			var foregift = CardMgnt.getFee(Constants.ACCOUNT_FOREGIFT_CARD,data.cardType.id);
			readCardForm.feeText.value = Format.fenToYuan(fee);
			readCardForm.foregiftText.value = Format.fenToYuan(foregift);
			
			pwdform.initBalance.value = Format.fenToYuan(data.cardType.initBalance);
		}catch(e){
			showError(e.description);
		}			
	}
	
	//售卡
	function doIssueCard(){
		var asn = readCardForm.asn.value;
		if (!CardMgnt.checkCardAsn(asn)) return;
		if (!showQuestion("是否出售不记名卡"+asn+"？")) {onCancel();return;}
		
		var initBalance = pwdform.initBalance.value;
		var data;
		try{
			data = DWR.syncCall("cardMgntService.issueAnonCard",asn,null);
		}catch(e){showError(e.description);return;}
		try{
			if (initBalance>0){
				//throw new Error("模拟不记名卡售卡损坏！");
				cardDeposit(asn,Format.yuanToFen(initBalance),AccountType.FUND,Constants.PAYMENT_CASH,null,Constants.DEFPIN);
				showInformation("充值成功!");
			}
		}catch(e){
			showError("不记名卡售卡充值失败："+e.description);
			
			if (showQuestion("不记名卡售卡充值失败！是否做不记名卡损坏登记？")){
				document.location.href = "bad_anoncard_reg.html?gotoIssue=true&asn="+asn;
			}else{
				onCancel();
			}
			return;
		}
		try{
			showIssueDet(data.logId);
			WebPrint.print("billview");
		}catch(e){
			showError("打印失败："+e.description);return;
		}
		var obj = Common.getValues(pwdform);
		var usePin = obj.usePin == "true";
		if (usePin)
			CardMgnt.startCardPin(asn);
		showInformation("售卡成功！");
	}
	
	//显示售卡明细,凭证预览
	function showIssueDet(logId){
		switchPage("detview");
		Eui.getBillHtml("billview",{
			queryName:"issue_anon_card_bill",
			logId:logId
		});
	}
	
	//重置、返回
	function onCancel(){
		switchPage("readcardview");
		readCardForm.reset();
		pwdform.reset();
		$("issueCardbtn").disabled = true;
	}
</script>
</head>
<body onload="load()">
<!--页面导航-->
<div class="nav"><div id="nav">&nbsp;</div></div>
<div id="readcardview">
	<div id="readcarddiv">
		<div class="form">
			<div class="formTitle">不记名卡售卡</div>
			<form id="readCardForm" name="readCardForm">
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="label6">
					<tr>
						<td><label>卡 号</label> <input type="text" name="asn" readonly class="readonly"></td>
						<td><label>卡类型</label> <input type="text" name="subCardTypeText" readonly class="readonly"></td>
					</tr>
					<tr>
						<td><label>押 金</label> <input type="text" name="foregiftText" readonly class="readonly"></td>
						<td><label>手续费</label> <input type="text" name="feeText" readonly class="readonly"></td>
					</tr>
				</table>
			</form>
			<form id="pwdform" name="pwdform">
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="label6">
					<tr>
						<td><label>卡内金额</label> <input type="text" name="initBalance" readonly class="readonly"></td>
						<td>
							<label>卡 密 码</label>
							&nbsp;<input type="radio" name="usePin" value="true">&nbsp;启用
							&nbsp;<input type="radio" name="usePin" value="false" checked>&nbsp;停用
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
	
	<p>
		<button onclick="onReadCard()">读 卡</button>
		<button id="issueCardbtn" onclick="doIssueCard()" disabled>售卡</button>
		<button onclick="onCancel()">重 置</button>
	</p>
</div>
<!--明细(新增)静态页面部分-->
	<!--售卡明细页面-->
	<div id="detview" class="form" style="width:100%;display:none;">
		<div class="formTitle">
			<div class="l">售卡凭证</div>
			<div class="r">
				<button onclick="WebPrint.preview('billview')">打印预览</button>
		 		<button onclick="WebPrint.print('billview')">打印</button>
		 		<button onclick="onCancel()">返 回</button>
			</div>
		</div>
		<div id="billview" align='center'></div>
	</div>

</body>
</html>